<?php

use yii\db\Migration;
use yii\db\Schema;
/**
 * 供应商信息表
 * 游轮公司
 */

class m161226_061243_create_db extends Migration
{
    public function up()
    {

        $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
        // 供应商信息
        $this->createTable('supplier', [
            "id" =>         Schema::TYPE_PK,
            "company" =>    Schema::TYPE_STRING.    "(255) NOT NULL COMMENT '公司名称'",
            "phone" =>      Schema::TYPE_STRING.    "(64) NULL COMMENT '联系方式'",
            "name" =>       Schema::TYPE_STRING.    "(32) NULL COMMENT '联系人'",
            "address" =>    Schema::TYPE_STRING.    "(255) NULL COMMENT '地址'",
            "mail" =>       Schema::TYPE_STRING.    "(255) NULL COMMENT '邮箱'",
            "desc" =>       Schema::TYPE_STRING.    "(1024) NULL COMMENT '描述'",
            "status" =>     Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '1正常  2禁用'",
            "user_id" =>    Schema::TYPE_INTEGER.   "(10) DEFAULT '0' COMMENT '管理员编号'",
            "created_at" => Schema::TYPE_DATETIME. " NULL",
            "updated_at" => Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
        ], $tableOptions);


        // 分销商信息
        $this->createTable('distribution', [
            "id" =>         Schema::TYPE_PK,
            "company" =>    Schema::TYPE_STRING.    "(255) NOT NULL COMMENT '分销商公司名称'",
            "phone" =>      Schema::TYPE_STRING.    "(64) NULL COMMENT '联系方式'",
            "name" =>       Schema::TYPE_STRING.    "(32) NULL COMMENT '联系人'",
            "mail" =>       Schema::TYPE_STRING.    "(255) NULL COMMENT '邮箱'",
            "address" =>    Schema::TYPE_STRING.    "(255) NULL COMMENT '地址'",
            "desc" =>       Schema::TYPE_STRING.    "(1024) NULL COMMENT '描述'",
            "status" =>     Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '1正常  2禁用'",
            "user_id" =>    Schema::TYPE_INTEGER.   "(10) DEFAULT '0' COMMENT '管理员编号'",
            "created_at" => Schema::TYPE_DATETIME. " NULL",
            "updated_at" => Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
        ], $tableOptions);



        //$this->addPrimaryKey("curr_code", "currency", "code");
        // 人员信息
        $this->createTable('member', [
            "id" =>         Schema::TYPE_PK,
            "name" =>       Schema::TYPE_STRING.    "(32) NULL COMMENT '姓名'",
            "phone" =>      Schema::TYPE_STRING.    "(64) NULL COMMENT '联系方式'",
            "mail" =>       Schema::TYPE_STRING.    "(255) NULL COMMENT '邮箱'",
            "password" =>   Schema::TYPE_STRING.    "(255) NULL COMMENT '密码'",
            "address" =>    Schema::TYPE_STRING.    "(255) NULL COMMENT '地址'",
            "position" =>   Schema::TYPE_STRING.    "(64) NULL COMMENT '职位'",
            "group" =>      Schema::TYPE_STRING.    "(128) NULL COMMENT '部门组'",
            "dist_id" =>    Schema::TYPE_INTEGER.   "(10) DEFAULT '0' COMMENT '所属分销商'",
            "type" =>       Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '1 内部员工  2 分销商人员 3 其它'",
            "desc" =>       Schema::TYPE_STRING.    "(128) NULL COMMENT '描述'",
            "status" =>     Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '1正常  2禁用'",
            "created_at" => Schema::TYPE_DATETIME.  " NULL",
            "updated_at" => Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
        ], $tableOptions);

    }

    public function down()
    {
        echo "m161226_061243_create_db cannot be reverted.\n";
        $this->dropTable('supplier');
        $this->dropTable('distribution');
        $this->dropTable('member');

        return false;
    }

    /*
    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
    }

    public function safeDown()
    {
    }
    */
}
